function wp = GET_WorkingPoint(obj, varargin)
%GET_WORKINGPOINT Summary of this function goes here
%   Detailed explanation goes here

    obj.controller.enableMagnetometerMainModulation();
    wp.frequency = obj.controller.getMagnetometerModulationFrequency();
    wp.amplitude = obj.controller.getMagnetometerModulationStrength();

    p=inputParser;

    levelCheck = @(x) x > 0.0 && x < 10.0;
    biasRangeCheck = @(x) x > 0.0 && x < 1.0;
    phaseRangeCheck = @(x) x > 1 && x <= 180;

    p.addParameter('biasY', obj.controller.CurrentSettings.ByCtrlDC.volt, levelCheck);
    p.addParameter('biasZ', obj.controller.CurrentSettings.BzCtrlDC.volt, levelCheck);
    p.addParameter('biasRawRange', 0.5, biasRangeCheck);
    p.addParameter('biasFineRange', 0.2, biasRangeCheck);
    p.addParameter('phaseFineRange', 10, phaseRangeCheck);
    p.addParameter('diableOutputSignal', false, @islogical);
    p.parse(varargin{:});
    
    obj.controller.ziMaster.setRange(3);
    obj.controller.enableMagnetometerModulateAmplitude();
    
    obj.controller.SetMagnetomiterDemodChannelState('scanWP');

    [phaseY0, phaseZ0, biasY0, biasZ0] = obj.scanPhaseBias('biasY', p.Results.biasY, ...
                                                           'biasZ', p.Results.biasZ, ...
                                                           'biasRange', p.Results.biasRawRange, ...
                                                           'phaseYRange', [0.0, 180.0], ...
                                                           'phaseZRange', [0.0, 180.0], ...
                                                           'name', 'RawScan' );

    phaseRange = p.Results.phaseFineRange;
    [phaseY, phaseZ, biasY, biasZ, stdY, stdZ, sseY, sseZ, slopeY, slopeZ] = obj.scanPhaseBias('biasY', biasY0, ...
                                                       'biasZ', biasZ0, ...
                                                       'biasRange', p.Results.biasFineRange, ...
                                                       'phaseYRange', phaseY0 + [-phaseRange, phaseRange], ...
                                                       'phaseZRange', phaseZ0 + [-phaseRange, phaseRange], ...
                                                       'name', 'FineScan' );
    if stdY > 0.001 || stdZ > 0.001
        warning('Too large std error during phase sweeping.');
    end
    if sseY > 0.001 || sseZ > 0.001
        warning('Bad fitting during bias sweeping.');
    end

    wp.phaseY = phaseY; wp.phaseZ = phaseZ;
    wp.biasY = biasY; wp.biasZ = biasZ;
    wp.stdY = stdY; wp.stdZ = stdZ;
    wp.sseY = sseY; wp.sseZ = sseZ;
    wp.slopeY = slopeY; wp.slopeZ = slopeZ;
    wp.coeffY = obj.controller.Conversions.ByDC.Volt2Mag*1e3 / slopeY; % nT/V
    wp.coeffZ = obj.controller.Conversions.BzAC.Volt2Mag*1e3 / slopeZ; % nT/V
    
    obj.workingPoint = wp;
    if p.Results.diableOutputSignal
        obj.controller.disableMagnetometerMainModulation();
    end
    
    % recover default settings of demod channels 
    obj.controller.SetMagnetomiterDemodChannelState('standard');
end

